#!c:/perl/bin/perl.exe

use lib "c:/wwcom/v2.0/cgi-bin";
use WiganRL::DataObject::Player;
use WiganRL::Search;
use CGI;
use strict;

my $cgi= CGI::new;
my $dbh= Diva::DB->new();
$dbh->set( {
	DATABASE_NAME		=> 'wwcom',
	DATABASE_SERVER		=> 'localhost:3306',
	DATABASE_USERNAME	=> 'wwcom',
	DATABASE_PASSWORD	=> 'wwcom',
	DATABASE_TYPE		=> 'mysql',
	} );
$dbh->connect();
$dbh->debug(0);


WiganRL::DataObject->dbh($dbh);
WiganRL::DataObject->cgi($cgi);
WiganRL::Search->dbh($dbh);

my $s= WiganRL::Search->new('PLAYER');
for (@{$s->search}) {
	if ($_->data('PLAYER_LASTNAME') eq '') {
		my (@name)= split(/\s+/,$_->data('PLAYER_FULLNAME'));
		if ($#name >= 0) {
			print "Updating player: ".$_->id."\n";
			$_->data('PLAYER_LASTNAME',$name[$#name]);
			$_->data('PLAYER_FIRSTNAME',$name[0]);
			$dbh->update('PLAYER',['PLAYER_LASTNAME','PLAYER_FIRSTNAME'],[$name[$#name],$name[0]],
				"FK_OBJECT_ID=".$_->id);
		}
	}
	
	my $fname= "c:/wwcom/v2.0/data/images/icons/".$_->data('PLAYER_LASTNAME').$_->data('PLAYER_FIRSTNAME')."Icon.gif";
	print "File: $fname\n";
	if (-e $fname && $_->data('PLAYER_ICON') eq '') {
		print "Updating player: ".$_->id."\n";
		$dbh->update('PLAYER',['PLAYER_ICON'],["data/images/icons/".$_->data('PLAYER_LASTNAME').$_->data('PLAYER_FIRSTNAME')."Icon.gif"],
			"FK_OBJECT_ID=".$_->id);
	}
}
	

sub tocgi {
	my ($o,$cgi)= @_;
	
	for (keys %{$o->data}) {
		$cgi->param($_,$o->data($_));
	}

	return;
}
